package com.localtime;

import org.junit.Test;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;

public class DateTimeFormatterDemo {
    private final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    @Test
    public void format() {
        System.out.println(LocalDateTime.now());
        System.out.println(dateTimeFormatter.format(LocalDateTime.now()));
        System.out.println(LocalDateTime.now().format(dateTimeFormatter));
    }

    @Test
    public void parse() {
        TemporalAccessor temporalAccessor = dateTimeFormatter.parse("2020-10-11 00:00:12");
        System.out.println(temporalAccessor);
        LocalDateTime localDateTime = LocalDateTime.from(temporalAccessor);
        System.out.println(localDateTime);
        LocalDateTime localDateTime1 = LocalDateTime.parse("2020-10-12 12:00:03", dateTimeFormatter);
        System.out.println(localDateTime1);
    }

    @Test
    public void parse1() {
        DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern(
                "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
        System.out.println(LocalDateTime.parse("2022-10-27T13:44:44.000Z",
                dateTimeFormatter1));
    }

    @Test
    public void getZone() {
        System.out.println(dateTimeFormatter.getZone());
    }

    @Test
    public void getLocale() {
        System.out.println(dateTimeFormatter.getLocale());
    }
}
